package com.firewolf.springcloud.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DeptController {
	
	@Autowired
	private DiscoveryClient client;//可以用来获取所有已经注入的微服务信息
	
	@RequestMapping("/servers/info")
	public Object servers(){
		List<String> services = client.getServices(); //获取注入的应用列表
		System.out.println(services);
		List<ServiceInstance> instances = client.getInstances("SERVICE-PROVIDER"); //根据应用的名字来获取注入的所有微服务
		for(ServiceInstance instance : instances){
			System.out.println(instance.getHost()+","+instance.getPort()+","+instance.getUri()+","+instance.getServiceId());
		}
		return client;
	}
}
